program highvoltage
  implicit none
  real  :: x1, x2, root
  print *, 'enter a bracket1'; read *, x1;print *, 'enter a bracket1'; read *, x2
  root = fs_secant(x1, x2, 0.00001)
  print *, 'root=', root
contains
  real function f(x) 
    real, intent(in)  ::  x
    f = x**3 - 5*x**2 - 29
  end function f

  recursive function fs_secant(x1, x2, convergence_limit)  result(root)
    real, intent(in)  ::  x1, x2, convergence_limit
    real              ::  x, y0, y1
    real              ::  root
    ! Start iteration
    y0=f(x1)
    y1=f(x2)
    ! Calculate new estimate
    ! Guard against y1-y0 too small
    if (abs(y1 - y0) < 0.001d0) y1 = y1 + 0.001d0
    x=( x1*y1 - x2*y0 )/(y1 - y0)
    print *,x
    ! Test for convergence
    if ( abs(f(x)) < convergence_limit ) then
      root = x
      return
    end if
    root = fs_secant(x, x2, convergence_limit)
  end
end program